package com.space.managegoods.controller;

import com.space.managegoods.po.GoodsInfoPO;
import com.space.managegoods.query.GoodsListQuery;
import com.space.managegoods.service.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangyaofeng
 * @version 1.0
 * @date 2023/9/11 14:21:18
 * @description
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    private static Logger logger = LoggerFactory.getLogger(GoodsController.class);
    @PostMapping(value = "/list")
    public Map list(@RequestBody GoodsListQuery goodsListQuery){
        Map<String,Object> result = new HashMap<>(2);
        try {
            List<GoodsInfoPO> goodsInfoPOS = goodsService.queryList(goodsListQuery);
            result.put("code",200);
            result.put("data",goodsInfoPOS);
            return result;
        }catch (Exception e){
            logger.error("查询出错",e);
            result.put("code",500);
            return result;
        }

    }
}
